package com.iot08.api.controller;

import com.iot08.api.service.mail.EmailService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author cwj
 * @description
 * @date 2025/5/7 11:37
 **/
@RestController
@RequestMapping("/mail")
public class EmailController {
    @Resource
    private EmailService emailService;

    @GetMapping("/send")
    @ResponseBody
    public String sendCode(@RequestParam String email) {
        String code = generateCode(); // 生成验证码
        emailService.sendVerifyCode(email, code);
        return "验证码已发送到：" + email;
    }

    private String generateCode() {
        return String.valueOf((int)((Math.random() * 9 + 1) * 100000)); // 6位随机验证码
    }
}
